using System;
using System.Threading;

namespace RedSkies
{
	public class FpsWaiter
	{
		private readonly FpsMax fpsMax; 
		private Int32 nextUpdate=0;
		
		public FpsWaiter (FpsMax fpsMax)
		{
			this.fpsMax = fpsMax;
		}
		
		public void WaitForSync()
		{
			if (fpsMax != FpsMax.Unlimited)
			{
				if (nextUpdate > System.Environment.TickCount)
				{
					Thread.Sleep(nextUpdate - System.Environment.TickCount);
				}
				nextUpdate = System.Environment.TickCount + (int)fpsMax;
			}				
		}
			
	}
}

